<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="五育id" prop="educationId">
      <el-input v-model="dataForm.educationId" placeholder="五育id"></el-input>
    </el-form-item>
    <el-form-item label="五育大主题id" prop="eduthemeId">
      <el-input v-model="dataForm.eduthemeId" placeholder="五育大主题id"></el-input>
    </el-form-item>
    <el-form-item label="大主题对应方面id" prop="eduaspectId">
      <el-input v-model="dataForm.eduaspectId" placeholder="大主题对应方面id"></el-input>
    </el-form-item>
    <el-form-item label="关键词" prop="keys">
      <el-input v-model="dataForm.keys" placeholder="关键词"></el-input>
    </el-form-item>
    <el-form-item label="关键词等级" prop="keysLevel">
      <el-input v-model="dataForm.keysLevel" placeholder="关键词等级"></el-input>
    </el-form-item>
    <el-form-item label="学生类型" prop="studentType">
      <el-input v-model="dataForm.studentType" placeholder="学生类型"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="创建者" prop="createBy">
      <el-input v-model="dataForm.createBy" placeholder="创建者"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="更新者" prop="updateBy">
      <el-input v-model="dataForm.updateBy" placeholder="更新者"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          educationId: '',
          eduthemeId: '',
          eduaspectId: '',
          keys: '',
          keysLevel: '',
          studentType: '',
          createTime: '',
          createBy: '',
          updateTime: '',
          updateBy: ''
        },
        dataRule: {
          educationId: [
            { required: true, message: '五育id不能为空', trigger: 'blur' }
          ],
          eduthemeId: [
            { required: true, message: '五育大主题id不能为空', trigger: 'blur' }
          ],
          eduaspectId: [
            { required: true, message: '大主题对应方面id不能为空', trigger: 'blur' }
          ],
          keys: [
            { required: true, message: '关键词不能为空', trigger: 'blur' }
          ],
          keysLevel: [
            { required: true, message: '关键词等级不能为空', trigger: 'blur' }
          ],
          studentType: [
            { required: true, message: '学生类型不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          createBy: [
            { required: true, message: '创建者不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          updateBy: [
            { required: true, message: '更新者不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/eas/eascommentkeys/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.educationId = data.easCommentKeys.educationId
                this.dataForm.eduthemeId = data.easCommentKeys.eduthemeId
                this.dataForm.eduaspectId = data.easCommentKeys.eduaspectId
                this.dataForm.keys = data.easCommentKeys.keys
                this.dataForm.keysLevel = data.easCommentKeys.keysLevel
                this.dataForm.studentType = data.easCommentKeys.studentType
                this.dataForm.createTime = data.easCommentKeys.createTime
                this.dataForm.createBy = data.easCommentKeys.createBy
                this.dataForm.updateTime = data.easCommentKeys.updateTime
                this.dataForm.updateBy = data.easCommentKeys.updateBy
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/eas/eascommentkeys/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'educationId': this.dataForm.educationId,
                'eduthemeId': this.dataForm.eduthemeId,
                'eduaspectId': this.dataForm.eduaspectId,
                'keys': this.dataForm.keys,
                'keysLevel': this.dataForm.keysLevel,
                'studentType': this.dataForm.studentType,
                'createTime': this.dataForm.createTime,
                'createBy': this.dataForm.createBy,
                'updateTime': this.dataForm.updateTime,
                'updateBy': this.dataForm.updateBy
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
